package com.example.demojenkins.config;

import com.example.demojenkins.filter.RequestLoggingFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @version 1.0
 * @author: LZ
 * @description:
 * @since 2025-06-19 14:52
 */
@Configuration
public class FilterConfig {
    @Bean
    public FilterRegistrationBean<RequestLoggingFilter> loggingFilterRegistration() {
        FilterRegistrationBean<RequestLoggingFilter> registration = new FilterRegistrationBean<>();
        registration.setFilter(new RequestLoggingFilter());

        // 设置过滤器的顺序，数字越小优先级越高
        registration.setOrder(Integer.MIN_VALUE);

        // 设置过滤器拦截的URL模式
        registration.addUrlPatterns("/*");

        // 可以排除特定路径
        // registration.addInitParameter("excludedUrls", "/static/*,/error");

        return registration;
    }
}
